﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DrinkTest.Question;

namespace DrinkTest.Answer
{
    public class Bob : IDrinkTest
    {
        public long GetSumSat(int[] S, int[] A)
        {
            if (S.Length != A.Length)
            {
                return 0;
            }

            if (A.Sum() < 100)
            {
                return -1;
            }

            Dictionary<int, int> data = new Dictionary<int, int>();

            for (int i = 0; i < S.Length; i++)
            {
                data.Add(S[i], A[i]);
            }


            var newData = from pair in data orderby pair.Key descending select pair;

            int init = 100;
            long res = 0;
            foreach (KeyValuePair<int, int> kvp in newData)
            {
                if (init < kvp.Value)
                {
                    return res + init * kvp.Key;
                }
                else
                {
                    res += kvp.Value * kvp.Key;
                    init -= kvp.Value;
                }
            }
            return res;
        }
    }
}
